package cn.wcy.design_patterns.creationtype01.abstractfactory02.impl;


import cn.wcy.design_patterns.creationtype01.abstractfactory02.CacheService;
import cn.wcy.design_patterns.creationtype01.abstractfactory02.Factory;
import cn.wcy.design_patterns.creationtype01.abstractfactory02.matter.RedisUtils;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class CacheServiceImpl implements CacheService {

    private final RedisUtils redisUtils = new RedisUtils();

    public String get(String key) {
        throw new UnsupportedOperationException("UnsupportedOperation");
    }

    public void set(String key, String value) {
        redisUtils.set(key, value);
    }

    public void set(String key, String value, long timeout, TimeUnit timeUnit) {
        redisUtils.set(key, value, timeout, timeUnit);
    }

    public void del(String key) {
        redisUtils.del(key);
    }

    @Override
    public void afterPropertiesSet(){
        Factory.register(this.getClass().getSimpleName(), this);
    }
}
